<?php
	function renderEnrolmentHead()
	{
		echo '<head><base href="../../assets/" />
		<title>School Enrolment :: Enrolment Form</title>
		<link type="text/css" href="styles.css" rel="stylesheet" />
		<link type="text/css" href="tabs.css" rel="stylesheet" />
		<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
		<script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
		<script type="text/javascript" src="js/jquery.ui.tabs.js"></script>
		<script type="text/javascript" src="js/Enrolment.js"></script></head>';
	}
	function getRadioButtons($values, $selectedValue, $name)
	{
		$t = '';
		$b = '';
		for($a = 0; $a < count($values); $a++)
		{
			$s = $values[$a];
			if($selectedValue == $s)
			{
				$b = "checked = 'true'";
			}
			$t .= "<input type='radio' name='$name' $b />$s<br />";
		}
		//Select a default if none is selected.
		if($b == '')
		{
			//KLUDGE:		$values[0]		Invalid selected output.
			$t = getRadioButtons($values, $values[0], $name);
		}
		//
		return $t;
	}
	function getEnrolmentParentsMarriageType($selectedValue)
	{
		return getRadioButtons(array('Catholic Church', 'Civil Marriage'),
								$selectedValue,
								'parents-marriage-type');
	}
	function getEnrolmentStudentStatus($selectedValue)
	{
		return getRadioButtons(array('New Student', 'Old Student', 'Returning Student'),
								$selectedValue,
								'status');
	}
	function getEnrolmentGender($selectedValue)
	{
		return getRadioButtons(array('Male', 'Female'), $selectedValue, 'sex');
	}
	function getEnrolmentHasBehaviorIssues($selectedValue)
	{
		return getRadioButtons(array('Yes', 'No'), $selectedValue, 'has-behavior-issues');
	}
	function getEnrolmentMedicalConditions($selectedValue)
	{
		return getRadioButtons(array('Yes', 'No'), $selectedValue, 'has-medical-conditions');
	}
	function getEnrolmentHasAllergies($selectedValue)
	{
		return getRadioButtons(array('Yes', 'No'), $selectedValue, 'has-allergies');
	}
	function getEnrolmentMarriedParents($selectedValue)
	{
		return getRadioButtons(array('Yes', 'No'), $selectedValue, 'married-parents');
	}
	function getEnrolmentTakesCare($selectedValue)
	{
		$l = array('Godparents &amp; Relatives',
					'Orphan House',
					'Older Brother and / or Sister',
					'Other peole who are not Relatives',
					'Others');
		$u = getRadioButtons($l, $selectedValue, 'takes-care');
		$u .= '<label for="takes-care-specify">Specify: </label>';
		$u .= '<input type="text" name="takes-care-specify" />';
		return $u;
	}
	function getParentsAbsenceReason($selectedValue)
	{
		$l = array('Working Abroad',
					'Mother or Father is dead',
					'Mother and Father are separated',
					'Others');
		$u = getRadioButtons($l, $selectedValue, 'parents-absence-reason');
		$u .= '<label for="parents-absence-reason-specify">Specify: </label>';
		$u .= '<input type="text" name="parents-absence-reason-specify" />';
		return $u;
	}
	function getEnrolmentPrimarilyLivesWith($selectedValue)
	{
		$l = array('Both Parents', 'Mother only', 'Father only', 'Others');
		$u = getRadioButtons($l, $selectedValue, 'lives-with');
		$u .= '<label for="lives-with-specify">Specify: </label>';
		$u .= '<input type="text" name="lives-with-specify" />';
	}
	function getEnrolmentYearLevels($selectedValue)
	{
		$l = array('T', 'Nursery', 'Kindargarten', 'Preparatory');
		$u = '<select name="year-level">';
		for($a = 0; $a < count($l); $a++)
		{
			$s = $l[$a];
			$t = '';
			if($selectedValue == $s) $t = ' selected="selected"';
			$u .= '<option' . $t . '>' . $s .'</option>';
		}
		$u .= '</select>';
		return $u;
	}
	function getEnrolmentFormValue($actionType, $value)
	{
		require_once '../../Controllers/EnrolmentController.php';
		$s = '';
		switch($actionType)
		{
			case EnrolmentController::CREATE:
				//Do nothing.
			break;
			case EnrolmentController::UPDATE:
				$s = "value='$value'";
			break;
		}
		return $s;
	}
	//@$studentModel		Pass $_POST if $actionType = UPDATE.
	function renderEnrolmentForm($actionType, $departmentType, $studentModel = null)
	{
		require_once '../../Controllers/EnrolmentController.php';
		//
	//	$f = getEnrolmentFormValue;
		//
		$m = $studentModel;
		$d = $departmentType;
		$sLabel = $d == EnrolmentController::ELEMENTARY ? 'Elementary' : 'Pre-Elementary';
		$tabCount = $d == EnrolmentController::PRE_ELEMENTARY ? 'tab1' : 'tab2';
		echo '<div id="' . $tabCount . '" class="tab_content">';
		//
		echo '<input type="checkbox" name="enrolment-status" class="enrolment-form-toggle" id="enrolment-status-' . $d . '" /> Show Form';
		echo '<form name="enrolment-form" class="enrolment-form" id="' . $d . '" method="post">
                <table cellpadding="0" align="center">
                  <tr>
                    <th>ENROLMENT FORM</th>
                  </tr>
				  <tr>
                    <td><label for="student-id">Student ID: </label></td>
					<td><input type="text" name="student-id" ' . getEnrolmentFormValue($actionType, $m['StudentId']) . ' /></td>
				  </tr>
                  <tr>
                    <td><label for="school-year">School Year:</label></td>
                    <td><input type="text" name="school-year" ' . getEnrolmentFormValue($actionType, $m['SchoolYear']) . ' /></td>
                    <td><label for="grade">Year Level:</label></td>
                    <td>' .
					  getEnrolmentYearLevels($m['YearLevel']) .
                    '</td>
                  </tr>
                  <tr>
                    <td colspan="3">
                    <?php getEnrolmentStudentStatus(' . $m['Status'] . ') ?>
                    </td>
                    </tr>
                    <tr><td>&nbsp;</td></tr>
                    <tr>
                    <th colspan="2">STUDENT\'S DETAILS</th>
                  </tr>
                 <tr>
                   <td><label for="name">Student\'s Name: </label></td>
                   <td><input type="text" name="name" ' . getEnrolmentFormValue($actionType, $m['Name']) . ' /></td>
                   <td><label for="birth-date">Birth Date: </label></td>
                   <td><input type="text" name="birth-date" ' . getEnrolmentFormValue($actionType, $m['BirthDate']) . ' /></td>
                 </tr>
                 <tr>
                   <td><label for="nickname">Nickname: </label></td>
                   <td><input type="text" name="nickname" ' . getEnrolmentFormValue($actionType, $m['Nickname']) . ' /></td>
                   <td><label for="age">Age:</label></td>
                   <td><input type="text" name="age" ' . getEnrolmentFormValue($actionType, $m['Age']) . ' /></td>
                 </tr>
                  <tr>
                    <td><label for="home-number">Home Phone Number: </label></td>
                    <td><input type="text" name="home-number" ' . getEnrolmentFormValue($actionType, $m['HomeNumber']) . ' /></td>
                    <td><label for="address">Address:</label></td>
                    <td><input type="text" name="address" ' . getEnrolmentFormValue($actionType, $m['Address']) . ' /></td>
                  </tr>
                  <tr>
                    <td><label for="religion">Religion:</label></td>
                    <td><input type="text" name="religion" ' . getEnrolmentFormValue($actionType, $m['Religion']) . ' /></td>
                    <td><label for="nationality">Nationality:</label></td>
                    <td><input type="text" name="nationality" ' . getEnrolmentFormValue($actionType, $m['Nationality']) . ' /></td>
                  </tr>
                  <tr>
                   <td><label for="sex">Sex: </label></td>
                   <td>' .
					 getEnrolmentGender($m['Sex']) .
                   '</td>
                  </tr>
                  <tr>
                   <td><label for="school-attended">School attended (if transferee) <br />(if transferee): </label></td>
                   <td><input type="text" name="school-attended" ' . getEnrolmentFormValue($actionType, $m['SchoolAttended']) . ' /></td>
                   <td><label for="school-year-attended">SY: </label></td>
                   <td><input type="text" name="school-year-attended" ' . getEnrolmentFormValue($actionType, $m['SchoolYearAttended']) . ' /></td>
                  </tr>
                  <tr>
                   <td><label for="lives-with">Student primarily lives with: </label></td>
                   <td colspan="2">' .
						getEnrolmentPrimarilyLivesWith($m['PrimarilyLivesWith']) .
                   '</td>
                  </tr>
  		            <tr>
                    <td><label for="parents-absence-reason">If both parents are absent,
					please indicate the reasons of absence by checking one of the answers below: </label></td>
                   <td colspan="2">' .
						getParentsAbsenceReason($m['ParentsAbsenceReason']) .
                   '</td>
                 </tr>
  		           <tr>
                   <td><label for="takes-care">If both parents are absent, who takes care of the child? </label></td>
                   <td colspan="2">' .
						getEnrolmentTakesCare($m['TakesCare']) .
                   '</td>
                 </tr>
                 <tr>
                   <th colspan="2">PARENT\'S DETAILS</th>
                 </tr>
                 <tr>
                   <td><label for="fathers-name">Father\'s Name: </label></td>
                   <td><input type="text" name="fathers-name" ' . getEnrolmentFormValue($actionType, $m['FathersName']) . ' /></td>
                   <td><label for="fathers-cellphone">Cellphone No.</label></td>
                   <td><input type="text" name="fathers-cellphone" ' . getEnrolmentFormValue($actionType, $m['FathersCellphone']) . ' /></td>
                 </tr>
                 <tr>
                   <td><label for="fathers-occupation">Occupation: </label></td>
                   <td><input type="text" name="fathers-occupation" ' . getEnrolmentFormValue($actionType, $m['FathersOccupation']) . ' /></td>
                   <td><label for="fathers-office-number">Office Phone No.</label></td>
                   <td><input type="text" name="fathers-office-number" ' . getEnrolmentFormValue($actionType, $m['FathersOfficeNumber']) . ' /></td>
                 </tr>
                 <tr>
                   <td><label for="mothers-name">Mother\'s Name:</label></td>
                   <td><input type="text" name="mothers-name" ' . getEnrolmentFormValue($actionType, $m['MothersName']) . ' /></td>
                   <td><label for="mothers-cellphone">Cellphone No.</label></td>
                   <td><input type="text" name="mothers-cellphone" ' . getEnrolmentFormValue($actionType, $m['MothersCellphone']) . ' /></td>
                 </tr>
               <tr>
                 <td><label for="mothers-occupation">Occupation: </label></td>
                 <td><input type="text" name="mothers-occupation" ' . getEnrolmentFormValue($actionType, $m['MothersOccupation']) . ' /></td>
                 <td><label for="mothers-office-number">Office Phone No.</label></td>
                 <td><input type="text" name="mothers-office-number" ' . getEnrolmentFormValue($actionType, $m['MothersOfficeNumber']) . ' /></td>
               </tr>
               <tr>
                 <td><label for="married-parents">Married: </label></td>
                 <td colspan="2">' .
						getEnrolmentMarriedParents($m['MarriedParents']) .
                  '</td>
                </tr>
                <tr>
			        <td><label for="married">If yes, where?: </label></td>
			        <td colspan="2">' .
						getEnrolmentParentsMarriageType($m['ParentsMarriageType']) .
					'</td>
               </tr>
               <tr>
                 <td colspan="4">
                   <h3><strong>EMERGENCY CONTACTS</strong></h3><br />
                   <em>The emergency contact person must be somebody other than the parents.</em>
                 </td>
               </tr>
               <tr>
                 <td><label for="emergency-guardian-name[]">1. Name:</label></td>
                 <td><input type="text" name="emergency-guardian-name[]" ' . getEnrolmentFormValue($actionType, $m['EmergencyGuardianName1']) . ' /></td>
                 <td><label for="emergency-guardian-cellphone[]">Home/Cellphone No.</label></td>
                 <td><input type="text" name="emergency-guardian-cellphone[]" ' . getEnrolmentFormValue($actionType, $m['EmergencyGuardianCellphone1']) . ' /></td>
               </tr>
               <tr>
                 <td><label for="emergency-guardian-relationship[]">Relationship to child:</label></td>
                 <td><input type="text" name="emergency-guardian-relationship[]" ' . getEnrolmentFormValue($actionType, $m['EmergencyGuardianRelationShip1']) . ' /></td>
               </tr>
               <tr>
                 <td><label for="emergency-guardian-name[]">2. Name:</label></td>
                 <td><input type="text" name="emergency-guardian-name[]" ' . getEnrolmentFormValue($actionType, $m['EmergencyGuardianName2']) . ' /></td>
                 <td><label for="emergency-guardian-cellphone[]">Home/Cellphone No.</label></td>
                 <td><input type="text" name="emergency-guardian-cellphone[]" ' . getEnrolmentFormValue($actionType, $m['EmergencyGuardianCellphone2']) . ' /></td>
               </tr>
               <tr>
                 <td><label for="emergency-guardian-relationship[]">Relationship to child:</label></td>
                 <td><input type="text" name="emergency-guardian-relationship[]" ' . getEnrolmentFormValue($actionType, $m['EmergencyGuardianRelationship2']) . ' /></td>
               </tr>
               <tr>
                 <td colspan="4"><h3><strong>GENERAL INFORMATION ABOUT YOUR CHILD</strong></h3></td>
               </tr>
               <tr>
                 <td colspan="2"><label for="has-allergies">Does your child have any allergies?</label></td>
                 <td>' .
					getEnrolmentHasAllergies($m['HasAllergies']) .
                 '</td>
               </tr>
               <tr>
                 <td colspan="4"><p>If YES, please provide a detailed explanation of signs,symptoms and treatment needed.</p></td>
               </tr>
               <tr><td colspan="3"><textarea name="allergy-details" cols="40" rows="10"> ' . $m['AllergyDetails'] . '</textarea></td>
               </tr>
               <tr>
                 <td colspan="2"><label for="has-medical-conditions">Does your child have any medical
				 condition/impairment/disability that you feel we need to know about?</label></td>
                 <td>' .
					getEnrolmentMedicalConditions($m['HasMedicalConditions']) .
                 '</td>
               </tr>
               <tr>
                 <td colspan="4"><p>If YES - please provide a detailed explanation of what it is for and
				 if there are any details our staff should know in order to provide care for your child
				 and special understanding where needed.</p></td>
               </tr>
               <tr><td colspan="3">
					<textarea name="has-medical-condition-details" cols="40" rows="10">' .
						$m['HasMedicalConditionDetails'] .
					'</textarea></td></tr>
               <tr>
                 <td colspan="2"><label for="has-behavior-issues">Does your child have behavior management issues?</label><br />
                  <em> (Example - ADHD, fears or phobias, non-responsive, uncooperative etc.)</em>
                   </td>
                 <td>' .
				   getEnrolmentHasBehaviorIssues($m['HasBehaviorIssues']) .
                 '</td>
               </tr>
               <tr>
                 <td colspan="4"><p>If YES - please specify what medical condition, who it was diagnosed by,
				 how it affects your child and management plans are in place including medication.</p></td>
               </tr>
               <tr><td colspan="3"><textarea name="has-behavior-issue-details" cols="40" rows="10">' .
						$m['HasBehaviorIssueDetails'] .
					'</textarea></td></tr>
               <tr>
                 <td colspan="4"><p>What other information(s) regarding your child that you feel our staff should be aware of?</p></td>
               </tr>
               <tr>
                 <td colspan="3"><textarea name="child-info-others" rows="10" cols="40">' . $m['ChildInfoOthers'] . '</textarea></td>
               </tr>
               <tr>
                 <td><input type="submit" name="enrol" value="Enrol ' . $sLabel . '" /></td>
               </tr>
             </table>
           </form>';
		echo '</div>';
	}
?>